import os
from playsound import playsound
import createAlphabet as ab

# 默认使用playsound库播放语音，因字母编码问题大概率打开失败则调用系统播放器打开文件
def playPaliWord(paliWord):
    try:
        playsound("./audio/words/%s.wav" % paliWord)
    except BaseException:
        print("播放 audio/words/%s.wav 失败，正在尝试使用本地播放器打开音频" % paliWord)
        os.startfile(os.getcwd() + "\\audio\\words\\%s.wav" % paliWord)


# 利用语音源拼出单词的读音,返回单词读音文件的相对地址
def spellWords(paliWord):
    betList = paliWord.split('-')
    if len(betList) == 0 or paliWord == ' ':
        pass
    if os.path.exists("audio/words/%s.wav" % paliWord):
        return "audio/words/%s.wav" % paliWord
    else:
        print('首次查询，读音正在生成······')



# 对于单个巴利语单词进行音节划分
def syllabification(rawPaliWord):
    pass


if __name__ == '__main__':
    playPaliWord('ā')
